package com.zpark.resume.controller;

import com.zpark.resume.common.ResponseResult;
import com.zpark.resume.common.StatusCode;
import com.zpark.resume.entity.Education;
import com.zpark.resume.entity.Experience;
import com.zpark.resume.service.IExperienceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PackageName: com.zpark.resume.controller
 * @ClassName: ExperienceController
 * @Description:
 * @author: RZS
 * @date: 2023/6/1  18:09
 */
@RestController
@CrossOrigin
@RequestMapping("/experience")
public class ExperienceController {

    @Autowired
    private IExperienceService experienceService;

    /**
     * 根据cv_id查询Experience数据
     * @param id cv_id
     * @return
     */
    @PostMapping("/find_by_cv_id/{id}")
    public ResponseResult<List<Experience>> findRecommendByCvId(@PathVariable("id") Integer id){
        // 调用业务层接口查询数据
        List<Experience> lists = experienceService.findByCvId(id);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), lists);
    }

    /**
     * 添加工作经历数据
     * @param experience
     * @return
     */
    @PostMapping("/add")
    public ResponseResult<Void> addExperience(@RequestBody Experience experience){
        // 调用业务层接口执行添加数据操作
        experienceService.addExperience(experience);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }

    /**
     * 修改工作经历
     * @param experience
     * @return
     */
    @PostMapping("/update")
    public ResponseResult<Void> changeExperience(@RequestBody Experience experience){
        // 调用业务层接口执行添加数据操作
        experienceService.changeExperience(experience);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }

    /**
     * 删除工作经历
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public ResponseResult<Void> removeExperience(@PathVariable("id") Integer id){
        // 调用业务层接口执行添加数据操作
        experienceService.removeExperience(id);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }
}
